<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"  %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="pg" uri="http://jsptags.com/tags/navigation/pager" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
	<div class="main-content">
				<!-- #section:basics/content.breadcrumbs -->
				<div class="breadcrumbs" id="breadcrumbs">
					<script type="text/javascript">
						try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
					</script>

					<ul class="breadcrumb">
						<li>
							<i class="ace-icon fa fa-home home-icon"></i>
							<a href="#">Home</a>
						</li>

						<li>
							<a href="#">Tables</a>
						</li>
						<li class="active">Simple &amp; Dynamic</li>
					</ul><!-- /.breadcrumb -->

					<!-- #section:basics/content.searchbox -->
					<div class="nav-search" id="nav-search">
						<form class="form-search">
							<span class="input-icon">
								<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
								<i class="ace-icon fa fa-search nav-search-icon"></i>
							</span>
						</form>
					</div><!-- /.nav-search -->

					<!-- /section:basics/content.searchbox -->
				</div>

				<!-- /section:basics/content.breadcrumbs -->
				<div class="page-content">
					<!-- #section:settings.box -->
					<div class="ace-settings-container" id="ace-settings-container">
						<div class="btn btn-app btn-xs btn-warning ace-settings-btn" id="ace-settings-btn">
							<i class="ace-icon fa fa-cog bigger-150"></i>
						</div>

						<div class="ace-settings-box clearfix" id="ace-settings-box">
							<div class="pull-left width-50">
								<!-- #section:settings.skins -->
								<div class="ace-settings-item">
									<div class="pull-left">
										<select id="skin-colorpicker" class="hide">
											<option data-skin="no-skin" value="#438EB9">#438EB9</option>
											<option data-skin="skin-1" value="#222A2D">#222A2D</option>
											<option data-skin="skin-2" value="#C6487E">#C6487E</option>
											<option data-skin="skin-3" value="#D0D0D0">#D0D0D0</option>
										</select>
									</div>
									<span>&nbsp; Choose Skin</span>
								</div>

								<!-- /section:settings.skins -->

								<!-- #section:settings.navbar -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-navbar" />
									<label class="lbl" for="ace-settings-navbar"> Fixed Navbar</label>
								</div>

								<!-- /section:settings.navbar -->

								<!-- #section:settings.sidebar -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-sidebar" />
									<label class="lbl" for="ace-settings-sidebar"> Fixed Sidebar</label>
								</div>

								<!-- /section:settings.sidebar -->

								<!-- #section:settings.breadcrumbs -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-breadcrumbs" />
									<label class="lbl" for="ace-settings-breadcrumbs"> Fixed Breadcrumbs</label>
								</div>

								<!-- /section:settings.breadcrumbs -->

								<!-- #section:settings.rtl -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-rtl" />
									<label class="lbl" for="ace-settings-rtl"> Right To Left (rtl)</label>
								</div>

								<!-- /section:settings.rtl -->

								<!-- #section:settings.container -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-add-container" />
									<label class="lbl" for="ace-settings-add-container">
										Inside
										<b>.container</b>
									</label>
								</div>

								<!-- /section:settings.container -->
							</div><!-- /.pull-left -->

							<div class="pull-left width-50">
								<!-- #section:basics/sidebar.options -->
								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-hover" />
									<label class="lbl" for="ace-settings-hover"> Submenu on Hover</label>
								</div>

								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-compact" />
									<label class="lbl" for="ace-settings-compact"> Compact Sidebar</label>
								</div>

								<div class="ace-settings-item">
									<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-highlight" />
									<label class="lbl" for="ace-settings-highlight"> Alt. Active Item</label>
								</div>

								<!-- /section:basics/sidebar.options -->
							</div><!-- /.pull-left -->
						</div><!-- /.ace-settings-box -->
					</div><!-- /.ace-settings-container -->

					<!-- /section:settings.box -->
					<div class="page-content-area">
						<div class="page-header">
							<h1>
								学生信息
								<small>
									<i class="ace-icon fa fa-angle-double-right"></i>
									Students Message
								</small>
							</h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<div class="row">
									<div class="col-xs-12">
										
										<div class="row">
												<div class="col-xs-6">
													<button type="button" class="btn btn-primary" id="bathAddBtn">
													  <span class="glyphicon glyphicon-plus" aria-hidden="true">批量增加</span>
													</button>
												</div>
										</div>
										
										
										<table id="sample-table-1" class="table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th align="center">
														<button type="button" class="btn btn-primary btn-xs saveStuBtn">增加学生</button>
													</th>
													<th>学号</th>
													<th>姓名</th>
													<th>性别</th>
													<th>出生年月</th>
													<th>电话</th>
													<th>住址</th>
													<th>操作</th>
												</tr>
											</thead>

											<tbody>
											<c:forEach items="${stuList.dates}" var="stu">
												<tr>
													<td class="center">
														<label class="position-relative">
															<input type="checkbox" class="ace">
															<span class="lbl"></span>
														</label>
													</td>
													<td>${stu.userId }</td>
													<td>${stu.userName }</td>
													<c:if test="${stu.gender==0 }">
														<td>男</td>
													</c:if>
													<c:if test="${stu.gender==1 }">
														<td>女</td>
													</c:if>
													<td>${stu.birthday }</td>
													<td>${stu.tel }</td>
													<td>${stu.address }</td>
													<td>
														<button class="btn btn-xs btn-info updateStuBtn">
															<i class="ace-icon fa fa-pencil bigger-120"></i>
														</button>&nbsp;
														<button class="btn btn-xs btn-danger deleteStuBtn">
															<i class="ace-icon fa fa-trash-o bigger-120"></i>
														</button>&nbsp;
														<button class="btn btn-xs btn-primary showStuSub">
															<span class="glyphicon glyphicon-asterisk" aria-hidden="true"></span>
														</button>
													</td>
												</tr>
											</c:forEach>
										 </tbody>
										</table>
										<pg:pager url="students" items="${stuList.totalSize}" export="currentPageNumber=pageNumber" maxPageItems="5">   
											  <pg:first>   
											    <a href="${pageUrl}">首页</a>   
											  </pg:first>   
											  <pg:prev>   
											    <a href="${pageUrl }">上一页</a>   
											  </pg:prev>   
											  <pg:pages>   
											    <c:choose>   
											      <c:when test="${currentPageNumber eq pageNumber}">   
											        <font color="red">${pageNumber }</font>   
											      </c:when>   
											      <c:otherwise>   
											        <a href="${pageUrl }">${pageNumber }</a>   
											      </c:otherwise>   
											    </c:choose>   
											  </pg:pages>   
											  <pg:next>   
											    <a href="${pageUrl }">下一页</a>   
											  </pg:next>   
											  <pg:last>   
											    <a href="${pageUrl }">尾页</a>   
											  </pg:last>   
										</pg:pager> 
										
									</div><!-- /.span -->
								</div><!-- /.row -->
							<!-- <div class="hr hr-18 dotted hr-double"></div>	 -->			
						</div><!--col-xs-12-->
					</div><!--row-->
				</div><!-- /.page-content-area -->
			</div><!-- /.page-content -->
		</div><!-- /.main-content -->
		
		
		
		
		<!--增加学生的信息的模态框 -->
		<div class="modal fade" tabindex="-1" role="dialog" id="saveStuModal">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title">增加学生</h4>
		      </div>
		      <div class="modal-body">
					<form class="form-horizontal" id="saveStuForm">
					
					  <div class="form-group">
					    <label for="inputEmail3" class="col-sm-2 control-label">学号</label>
					    <div class="col-sm-4">
					      <input type="text" name="userId"  class="form-control" id="stuId" >
					    </div>
					  </div>
					  
					  <div class="form-group">
					    <label for="inputPassword3" class="col-sm-2 control-label">姓名</label>
					    <div class="col-sm-6">
					      <input type="text" name="userName"  class="form-control" id="userName" placeholder="userName">
					    </div>
					  </div>
					  
					  <div class="form-group">
					    <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
					    <div class="col-sm-6">
					      <input type="password" name="password"  class="form-control" id="password" placeholder="password">
					    </div>
					  </div>
					  
					  <div class="form-group">
					   <label for="inputPassword3" class="col-sm-2 control-label">性别</label>
					    <label class="radio-inline">
						  <input type="radio" name="gender" id="f"  value="0"> 男
						</label>
						<label class="radio-inline">
						  <input type="radio" name="gender" id="m"  value="1" > 女
						</label>
					  </div>
					  
					   <div class="form-group">
					   <label for="inputPassword3" class="col-sm-2 control-label">出生年月</label>
					     <div class="col-sm-6">
					      <input type="text" name="birthday" id="birthday"  class="form-control" placeholder="birthday,如2017-01-01">
					    </div>
					  </div>
					  
					   <div class="form-group">
					   <label for="inputPassword3" class="col-sm-2 control-label">电话号码</label>
					     <div class="col-sm-6">
					      <input type="text" name="tel" id="tel"  class="form-control" placeholder="telphone">
					    </div>
					  </div>
					  
					   <div class="form-group">
					   <label for="inputPassword3" class="col-sm-2 control-label">住址</label>
					     <div class="col-sm-6">
					      <input type="text" name="address" id="address"  class="form-control" placeholder="address">
					    </div>
					  </div>
					</form>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		        <button type="button" class="btn btn-primary" id="saveStudentBtn">保存</button>
		      </div>
		    </div><!-- /.modal-content -->
		  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->
		
		
		<!--修改学生的信息的模态框 -->
		<div class="modal fade" tabindex="-1" role="dialog" id="updateStuModal">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title">修改学生信息</h4>
		      </div>
		      <div class="modal-body">
					<form class="form-horizontal" id="updateStuForm">
					
					  <div class="form-group">
					    <label for="inputEmail3" class="col-sm-2 control-label">学号</label>
					    <div class="col-sm-4">
					      <input type="text" name="userId"  class="form-control" id="stuId" readonly="readonly">
					    </div>
					  </div>
					  
					  <div class="form-group">
					    <label for="inputPassword3" class="col-sm-2 control-label">姓名</label>
					    <div class="col-sm-6">
					      <input type="text" name="userName"  class="form-control" id="userName" placeholder="userName">
					    </div>
					  </div>
					  
					  <div class="form-group">
					    <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
					    <div class="col-sm-6">
					      <input type="password" name="password"  class="form-control" id="password" placeholder="password">
					    </div>
					  </div>
					  
					  <div class="form-group">
					   <label for="inputPassword3" class="col-sm-2 control-label">性别</label>
					    <label class="radio-inline">
						  <input type="radio" name="gender" id="f"  value="0"> 男
						</label>
						<label class="radio-inline">
						  <input type="radio" name="gender" id="m"  value="1" > 女
						</label>
					  </div>
					  
					   <div class="form-group">
					   <label for="inputPassword3" class="col-sm-2 control-label">出生年月</label>
					     <div class="col-sm-6">
					      <input type="text" name="birthday" id="birthday"  class="form-control" placeholder="birthday,如2017-01-01">
					    </div>
					  </div>
					  
					   <div class="form-group">
					   <label for="inputPassword3" class="col-sm-2 control-label">电话号码</label>
					     <div class="col-sm-6">
					      <input type="text" name="tel" id="tel"  class="form-control" placeholder="telphone">
					    </div>
					  </div>
					  
					   <div class="form-group">
					   <label for="inputPassword3" class="col-sm-2 control-label">住址</label>
					     <div class="col-sm-6">
					      <input type="text" name="address" id="address"  class="form-control" placeholder="address">
					    </div>
					  </div>
					</form>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		        <button type="button" class="btn btn-primary" id="updateStudentBtn">修改</button>
		      </div>
		    </div><!-- /.modal-content -->
		  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->
		
		
		<!-- 批量增加 -->
		<div class="modal fade" id="uploadFileModal" tabindex="-1" role="dialog">
			 <div class="modal-dialog" role="document">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title">文件上传</h4>
			      </div>
			      <div class="modal-body">
			      <form  enctype="multipart/form-data">
			        <input id="uploadFile" name="uploadFile" type="file"/>
			       </form>
			      </div>
			      
			      <div class="modal-footer">
			        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			        <button type="button" class="btn btn-primary" id="upfileSaveBtn">保存</button>
			      </div>
			    </div><!-- /.modal-content -->
			 </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->
		
		<!-- 展示学生关联的科目 -->
		<div class="modal fade" tabindex="-1" role="dialog" id="showStuSubModal">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title">选课的课程</h4>
		      </div>
		      <div class="modal-body">
		      	 <input type="hidden" id="stuId">
					<div id="subjectStudentContent" class="control-group">
						      		
					</div>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		        <button type="button" class="btn btn-primary" id="subjectStudentSaveBtn">保存</button>
		      </div>
		    </div><!-- /.modal-content -->
		  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->
		
		<script type="text/javascript">
		 //打开批量保存的模态框
		$("#bathAddBtn").click(function(){
			$("#uploadFileModal").modal({
				backdrop:"static"
		});
			
		});

		//文件上传的样式控制
		$("#uploadFile").ace_file_input({
			style:'well',
			btn_choose:'Drop files here or click to choose',
			btn_change:null,
			no_icon:'ace-icon fa fa-cloud-upload',
			droppable:true,
			thumbnail:'small',
			preview_error:function(filename,error_code){
				
			}
		}).on('change',function(){
			
		});

		//ajxa请求批量添加学生
		$("#upfileSaveBtn").click(function(){
			$.ajaxFileUpload({
				url:"${pageContext.request.contextPath }/stu/uploadFile",
				secureuri:false,
				fileElementId:"uploadFile",
				dataType:"json",
				complete:function(data){
					
				},
				success:function(data,status){
					if(data.code==100){
						alert("处理成功");
						$("#uploadFileModal").modal("hide");
						window.location.reload();
					}
					else{
						alert("处理不成功");
					}
				},
				error:function(data,status,e){
					alert(e);
				}
			 })
		})
		
		//展示学生关联的课程
		$('.showStuSub').click(function(){
			//学生的id
			var stuId=$(this).parent().siblings().eq(1).text();
			$.ajax({
				url:"${pageContext.request.contextPath }/stu/getStuSub",
				type:"POST",
				data:"stuId="+stuId,
				success:function(result){
					var htmlString='';
					var selectedSubject=result.map.selectedSubject;
					$.each(result.map.allSubject,function(index,item){
						var checked=checkSelectedUser(selectedSubject,item.subId)?'checked="checked"':'';
						htmlString +='<div class="checkbox">';
						htmlString +='	<label>';
						htmlString +='		<input name="subjectStudents" class="ace ace-checkbox-2" id="subCheckBox" type="checkBox" value="'+item.subId+'" '+checked+' />';
						htmlString +='		<span class="lbl">'+item.name+'</span>';
						htmlString +='	</label>';
						htmlString +='</div>';
					})
					$('#subjectStudentContent').html(htmlString);
					$('#stuId').val(stuId);
				}
			}) 
			$('#showStuSubModal').modal({
				backdrop:"static"
			})
		})
		
		//判断相应的id是否选上
		function checkSelectedUser(selectedUser,allUserId){
			for(var i=0;i<=selectedUser.length;i++){
				if(selectedUser[i]==allUserId){
					return true;
				}
			}
			return false;
		}
		
	/* 	$('input[name="subjectStudents"]').on('click',function(){
			alert("6666666");
		}) */
		//检测该学生是否已经参考过，参考过有一个分数,对于参考过的学生，我们不能修改他和课程的关联
		$(document).on('click','#subCheckBox',function(){
			var stuId=$('#stuId').val();
			var subId=$(this).val();
			$.ajax({
				url:'${pageContext.request.contextPath }/Score/getScoreBystuIdAndSubId',
				type:'POST',
				data:{
					stuId:stuId,
					subId:subId
				},
				success:function(result){
					if(result.map.score.examScore.score==null){
						
					}
					else{
						$('#subCheckBox').prop("checked",true);
						$('#subCheckBox').parent().parent().addClass("disabled");
						$('#subCheckBox').attr("disabled","disabled");
						alert("该学生下的该科目不可以修改，因为其已经参考");
					}
				}
				
			});
		});
		
		
		
		//改变学生的选课
		$('#subjectStudentSaveBtn').on('click',function(){
			var subjectStudents=new Array();
			//获取当前选中的学生，本质是获取当前选中学生id
			for(var i=0;i<$('input[name="subjectStudents"]:checked').length;i++){
				subjectStudents[i]=$($('input[name="subjectStudents"]:checked')[i]).val();
			}
			$.ajax({
				type:'POST',
				url:"${pageContext.request.contextPath }/stu/saveSubjectstudent",
				data:{
					//学生的Id
					stuId:$("#stuId").val(),
					//课程集合的id
					subjectStudents:subjectStudents
				},
				dataType:'json',
				success:function(result){
					alert(result.message);
					$("#showStuSubModal").modal("hide");
				}
			})
		})
		
		//打开修改的模态框
		$('.updateStuBtn').click(function(){
			var stuId=$(this).parent().siblings().eq(1).text();
			$.ajax({
				url:"${pageContext.request.contextPath }/stu/getStuById",
				type:"GET",
				data:"stuId="+stuId,
				success:function(result){
					var student=result.map.Student;
					$("#updateStuModal #stuId").val(student.userId);
					$("#updateStuModal #userName").val(student.userName);
					$("#updateStuModal #password").val(student.password);
					if(student.gender==0){
						$("#updateStuModal #f").prop("checked","checked");
					}
					else if(student.gender==1){
						$("#updateStuModal #m").prop("checked","checked");
					}
					$("#updateStuModal #birthday").val(student.birthday);
					$("#updateStuModal #tel").val(student.tel);
					$("#updateStuModal #address").val(student.address);
				}
			})
			$('#updateStuModal').modal({
				backdrop:"static"
			})
		})
		
		//进行修改的操作
		$('#updateStudentBtn').click(function(){
			$.ajax({
				url:"${pageContext.request.contextPath }/stu/updateStu",
				type:"POST",
				data:$('#updateStuForm').serialize(),
				success:function(result){
					alert(result.message);
					$('#updateStuModal').modal("hide");
					window.location.reload();
				}
			});
		})
		
		//删除的操作
		$('.deleteStuBtn').click(function(){
			var stuId=$(this).parent().siblings().eq(1).text();
			if(confirm("确认删除学号为:"+stuId+"的学生吗？")){
				$.ajax({
					url:"${pageContext.request.contextPath }/stu/deleteStu",
					type:"POST",
					data:"stuId="+stuId,
					success:function(result){
						alert(result.message);
						window.location.reload();
					}
				});
			}
		})
		
		
		//打开增加的模态框
		$('.saveStuBtn').click(function(){
			$('#saveStuModal').modal({
				backdrop:"static"
			})
		})
		
		
		//新增的功能
		$('#saveStudentBtn').click(function(){
			$.ajax({
				url:"${pageContext.request.contextPath }/stu/saveStu",
				type:"POST",
				data:$('#saveStuForm').serialize(),
				success:function(result){
					alert(result.message);
					window.location.reload();
				}
			})
		})
		</script>
</body>
</html>